package com.bike.common;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

import java.util.Random;

/**
 * 一些常量
 * @author linyuc
 * @date 2022/01/12 11:34
 */
public class Const {
    public static final String CURRENT_USER = "currentUser";
    public static final String USERNAME = "username";
    public static final String EMAIL = "email";
    public static final String PHONE = "phone";
    public static final Integer PAGE_DEFAULT_NUM = 1;
    public static final Integer PAGE_DEFAULT_SIZE = 10;
    public static final Integer NOTICE_IS_TOP = 1;
    /**
     * 用户账号状态：0：禁用，1：正常
     */
    public static final String USER_STATUS_ENABLE = "1";
    public static final String USER_STATUS_DISABLE = "0";

    public static final String USER_ROLE_NORMAL = "normal";
    public static final String USER_ROLE_ADMIN = "admin";

    public static void initPage(int current, int size){

    }
    public static long generateOrderNo(){
        long currentTime = System.currentTimeMillis();
        return currentTime + currentTime%10;
    }
    // 生成6位单车编号，大写字母开头加5位数字
    public static String generateBikeNo(){
        StringBuilder val = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            if(i == 0){
                val.append((char) (65 + random.nextInt(26)));
            }else{
                val.append((random.nextInt(10)));
            }
        }
        return val.toString();
    }
    //计算两个坐标距离
    public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo){

        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, gpsFrom, gpsTo);

        return geoCurve.getEllipsoidalDistance();
    }
}
